#! /usr/bin/env python
#
# Author : Galatolo Federico
# Date : 01/09/09
# Version : 0.1
#
# This is a Free Software relased under GNU/GPL
#
# CopyLeft 2009 Galatolo Federico :)


class confpars:
	buff = 1024
	file = ''
	conf = {}
	config = conf
	def open(self,ofile):
		try:
			self.file = open(ofile,"r")
		except:
			print "*** ConfPars Error *** : Can't open file",ofile
	def parse(self):
		read = ""
		while 1:
			try:
				read = self.file.readline(self.buff)
			except:
				print "*** ConfPars Error *** : Can't read the file"
			if not read:
				break
			if read != "\n":
				if read[0] == "#":
					comm = 1
				elif read[0] == "@":
					inc = 1
				else:	
					read_s = read.split('"')
					if read.split(" ")[1][0] == '"':
							self.conf[read.split(" ")[0]] = read_s[1]
					else:
						read_s = read.split(" ")
						if read_s[1][0:2] == "On":
							self.conf[read_s[0]] = True
						elif read_s[1][0:3] == "Off":
							self.conf[read_s[0]] = False
						else:
							try:
								self.conf[read_s[0]] = int(read_s[1])
							except:
								print "*** ConfPars Error *** : Incompatible Type, Please read README.txt"
		return self.conf

